package com.chinasoft.maysham.manager.controller.project;

import com.chinasoft.maysham.manager.controller.BaseController;
import com.chinasoft.maysham.manager.model.Project;
import com.chinasoft.maysham.manager.service.project.ProjectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/projects")
public class ProjectController extends BaseController {

    @Resource
    private ProjectService projectService;

    @PostMapping("/create")
    public Project create(@RequestBody Project project) {
        return projectService.create(project, currentUserId());
    }

    @GetMapping("/list")
    public List<Project> list(@RequestParam(defaultValue = "0", required = false) int page,
                              @RequestParam(defaultValue = "10", required = false) int size) {
        return projectService.list(page, size, currentUserId());
    }

    @PutMapping("/{projectId}/update")
    public Project update(@PathVariable String projectId, @RequestBody Project project) {
        return projectService.update(project, currentUserId(), projectId);
    }

    @DeleteMapping("/{projectId}/delete")
    public boolean delete(@PathVariable String projectId) {
        return projectService.delete(projectId, currentUserId());
    }

    @GetMapping("/{projectId}/info")
    public Project info(@PathVariable String projectId){
        return projectService.queryById(projectId);
    }
}
